package com.tensquare.jwt;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 创建jwttoken
 * @Author: fxx
 * @Date: 2021/1/13 19:59
 */
public class CreateJwt {
    public static void main(String[] args){
        Map<String, Object> map = new HashMap<>();
        map.put("role", "admin");
        JwtBuilder jwtBuilder = Jwts.builder()
                .setId("666")   //id
                .setSubject("小明") //用户名
                .setIssuedAt(new Date())    //登录时间
                .setExpiration(new Date(new Date().getTime() + 60000)) //过期时间：1分钟
                .setClaims(map) //自定义信息
                .signWith(SignatureAlgorithm.HS256, "itcast");
        System.out.println(jwtBuilder.compact());
    }
}
